package cn.breeze.user.controller;

import cn.breeze.mapper.UserMapper;
import cn.breeze.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//用户服务：暴露接口给订单访问
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;
 

    /*//订单服务来调用这个方法      http://localhost:1020/user/10
    // @GetMapping(value = "/user/{id}" )
    @RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
    public User getById(@PathVariable("id")Long id){
        //根据id去数据库查询User
        
        return  new User(id,"zs:"+id,"我是zs");
    }*/
    //加载端口
    @Value("${server.port}")
    private int port;

    //订单服务来调用这个方法      http://localhost:1020/user/10
    // @GetMapping(value = "/user/{id}" )
    @GetMapping(value = "/user/{id}")
    public User getById(@PathVariable("id")Long id){
        //根据id去数据库查询User
        System.out.println(port);
        return  User.builder().id(id).username("zs"+id).desc("我是zs").build();	//端口随User返回new User(id,"zs:"+id,"我是zs,port:"+port)
    }

    @GetMapping("/user/loadAll")
    public List<User> loadAll(){
        return userMapper.loadAll();
    }
}